#include <nall/platform.hpp>
#include "phoenix.hpp"
using namespace nall;
using namespace phoenix;

struct Application : Window {
  VerticalLayout layout;
  Canvas canvas;
  image logo;

  void create() {
    layout.setMargin(5);
    layout.append(canvas, {~0, ~0});
    append(layout);

    setTitle("phoenix");
    setGeometry({128, 128, 720, 180});
    setVisible();

    onClose = &OS::quit;
    onSize = [&] {
/*
      uint32_t *data = canvas.data();
      for(unsigned y = 0; y < canvas.size().height; y++) {
        for(unsigned x = 0; x < canvas.size().width; x++) {
          *data++ = 0x0000ff00;
        }
      }
      canvas.update();
      return;
*/
      auto geometry = canvas.geometry();
      image copy = logo;
      copy.scale(geometry.width, geometry.height, &Interpolation::Hermite);
      copy.alphaBlend(0xffffff);
      canvas.setImage(copy);
      canvas.update();
    };

    onSize();
  }

  Application() : logo(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) {
    logo.load("logo.png");
  }
} application;

int main() {
  application.create();
  OS::main();
  return 0;
}
